package com.example.mynews.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.mynews.Pojo.Pojo_listview;
import com.example.mynews.R;

import java.util.List;

public class listview_Adapter extends BaseAdapter {
  private List<Pojo_listview>list;
  private  Context context;

    public listview_Adapter(List<Pojo_listview> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHord hord;
        if (view==null)
        {
            view = LayoutInflater.from(context).inflate(R.layout.listview, viewGroup, false);
            hord=new ViewHord();
            hord.img=view.findViewById(R.id.iv_icon);
            hord.title=view.findViewById(R.id.tv_news_title);
            hord.date=view.findViewById(R.id.tv_news_date);
            view.setTag(hord);
        }else {
            hord = (ViewHord) view.getTag();
        }
        Glide.with(context).load("http://192.168.1.109:8080/web_home" + list.get(i).getIv_icon()).into(hord.img);
        hord.title.setText(list.get(i).getTv_news_title());
        hord.date.setText(list.get(i).getTv_news_date());
        return view;
    }
    class ViewHord{
        ImageView img;
        TextView title,date;
    }
}
